package my.maven.project;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class JsoupDemo {

	static String url = "http://www.iciba.com/confusion";

	public static void main(String[] args) {
		  
		try {

			Document doc = Jsoup.connect(url).get();

			Elements container = doc.getElementsByClass("container");

			Document containerDoc = Jsoup.parse(container.toString());

			Elements module = containerDoc.getElementsByClass("module-list");

			Document moduleDoc = Jsoup.parse(module.toString());

			// Elements clearfix = moduleDoc.getElementsByClass("clearfix"); //DOM的形式

			Elements clearfix = moduleDoc.select(".clearfix"); // 选择器的形式

			for (Element clearfixli : clearfix) {
				Document clearfixliDoc = Jsoup.parse(clearfixli.toString());
				Elements kind = clearfixliDoc.select(".board-tag"); // 选择器的形式
				Elements title = clearfixliDoc.select(".tit-post");
				Elements author = clearfixliDoc.select("span a");

				System.out.println("类别" + kind.text()); // 分类
				System.out.println("标题" + title.text()); // 标题
				System.out.println("作者" + author.text()); // 作者
				System.out.println("详情链接" + title.attr("href")); // 标题下的链接

				System.out.println("=====================");

			}
			// String title = clearfixli.getElementsByTag("a").text();

			// System.out.println(clearfix);

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
